#ifndef LOADMUSIC_H
#define LOADMUSIC_H

#include <QObject>
#include<thread>
#include<mutex>
#include<condition_variable>
#include<queue>
#include"tcpclient.h"
#include<QFile>
using namespace std;
class loadmusic : public QObject
{
    Q_OBJECT
    enum class MusicLoadState
    {
       Noload,     //没有下载
       loading,    //下载中
       endload     //下载结束
    };
public:
    explicit loadmusic(QString title,QObject *parent = nullptr);
    void run();
    inline void closeload(){  //关闭下载
        state=MusicLoadState::endload;
    }
    ~loadmusic();
private:
    static void receivenetwork(loadmusic*lm,QString title);
    static void GatherNetWork(loadmusic*lm,QString titile);
signals:
    void destory(loadmusic*ls);
    void play(QString title);
public:                            //线程同步类
     mutex  m_mtx;                   //添加资源的锁
     queue<QByteArray>m_data;        //数据队列
     condition_variable m_NoNull;    //不为空

     QString m_title;              //请求歌曲名字
     tcpclient*m_client;             //套接字
     QFile *m_file;

     MusicLoadState state;
};

#endif // LOADMUSIC_H
